package Manager;

import GameService.GameMap;
import UI.MainGamePanel;
import UI.ViewSettings;

import java.awt.event.*;

public class Mouse_Listener implements MouseListener {
    private MainGamePanel mainGamePanel;
    private GameMap gameMap;
    public Mouse_Listener(MainGamePanel mainGamePanel){
        this.mainGamePanel=mainGamePanel;
    }

    @Override
    public void mouseClicked(MouseEvent e) {
    }

    @Override
    public void mousePressed(MouseEvent e) {
        if(mainGamePanel.isRunning()) return;
        gameMap=mainGamePanel.getGameMap();
        int x=e.getX();
        int y=e.getY();
        if(x>mainGamePanel.getGameZone_x() && x< mainGamePanel.getGameZone_x()+ ViewSettings.GameZone.width
                && y> mainGamePanel.getGameZone_y() && y< mainGamePanel.getGameZone_y()+ViewSettings.GameZone.height)
        {
            int x1=(y- mainGamePanel.getGameZone_y())/ mainGamePanel.getSpace();
            int y1=(x- mainGamePanel.getGameZone_x()) / mainGamePanel.getSpace();
            if(gameMap.getCells()[x1][y1].isAlive()){
                gameMap.DeactivateCell(x1,y1);
            }
            else gameMap.ActivateCell(x1, y1);
            mainGamePanel.repaint();
        }
    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }

}
